<?php
/*
 * 无限级分类
 */

function generateTree($items){
    $tree = array();
    foreach($items as $item){
        if(isset($items[$item['pid']])){
            $items[$item['pid']]['son'][] = &$items[$item['id']];
        }else{
            $tree[] = &$items[$item['id']];
        }
    }
    return $tree;
}
/*
function generateTree($items){
    foreach($items as $item)
        $items[$item['pid']]['son'][$item['id']] = &$items[$item['id']];
    return isset($items[0]['son']) ? $items[0]['son'] : array();
}
 */
$items = array(
    1 => array('id' => 1, 'pid' => 0, 'name' => '中致远集团'),
    2 => array('id' => 2, 'pid' => 0, 'name' => '昆明宝远'),
    3 => array('id' => 3, 'pid' => 1, 'name' => '财务部'),
    4 => array('id' => 4, 'pid' => 3, 'name' => 'xx科'),
    5 => array('id' => 5, 'pid' => 1, 'name' => '信息管理部'),
);

$tree = generateTree($items);
print_r($tree);